package com.naton.mydemo.model.dao.converter;

import android.text.TextUtils;

import androidx.room.TypeConverter;

import com.naton.common.utils.JsonUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 字符串转换
 */
public class StringConverter {

    @TypeConverter
    public List<String> stringToList(String jsonStr) {
        if (TextUtils.isEmpty(jsonStr)){
            return new ArrayList<>();
        }
        return JsonUtils.INSTANCE.stringToListObject(jsonStr, String.class);
    }

    @TypeConverter
    public String listToString(List<String> list) {
        if (list != null){
            return JsonUtils.INSTANCE.toJsonString(list);
        }else {
            return "[]";
        }

    }
}
